﻿    var control2Focus="";var controlid=null; var includeEmptyCount = false;
    function setFocus(controlid2,includeEmptyCount2)//this function gets invoked first. Provides the loading image.
    {        
        if (document.getElementById("DIV_" + controlid2).style.display == "block")
        {
            //document.getElementById("DIV_" + controlid).style.display = "none";
            //document.getElementById("search_img_"+controlid).src = "Images/search.gif";
            //return;
        }
        else
        {
            //document.getElementById("DIV_" + controlid).style.display = "block";        
            document.getElementById("search_img_"+controlid2).src = "Images/load.gif";
        }
        controlid = controlid2;
        includeEmptyCount = includeEmptyCount2;
        setTimeout("setFocus2()",100);//calls the main function
    }
    function setFocus2()//this function displays the lookup div sets the value for setting the focus
    {
        //alert(document.getElementById("DIV_" + controlid).style.display);
        if (document.getElementById("DIV_" + controlid).style.display == "block")//changes the lookup display style
        {
            document.getElementById("DIV_" + controlid).style.display = "none";
            //document.getElementById("search_img_"+controlid).src = "Images/search.gif";
            return;
        }
        else
        {
            document.getElementById("DIV_" + controlid).style.display = "block";        
            //document.getElementById("search_img_"+controlid).src = "Images/close_15.gif";
        }
        try
        {        
            //alert(document.getElementById("ctl00_ContentPlaceHolder3_" + controlid).type);
            if (document.getElementById("ctl00_ContentPlaceHolder3_" + controlid).type=="text")//if the rendered control type is text box
            {
            
            }
            else//it is a drop down
            {
                //var index = document.getElementById("ctl00_ContentPlaceHolder3_p_lookup_id").selectedIndex;        
                var index = document.getElementById("ctl00_ContentPlaceHolder3_" + controlid).selectedIndex;//gets the index of the drop down        
                //var table = document.getElementById("tbl_div_p_lookup_id");
                if (includeEmptyCount==true && index==0)
                {
                    document.getElementById("search_img_"+controlid).src = "Images/search.gif";//make sure that the lookup icon is restored
                    return;//no record to select as the selected value is null;
                }
                if (includeEmptyCount) index--;//reduce the index since there is no first element in the lookup table
                index++;//adding due to the index change 
                var table = document.getElementById("tbl_div_" + controlid);//gets the lookup table
                var rows = table.getElementsByTagName("tr");//gets all the rows in that table                          
                for(var i=0;i<rows.length;i++)
                {
    //                if ((i+1)==index)
    //                {
    //                    document.getElementById("img_"+ controlid+i).src = "Images/check.gif";
    //                }
    //                else
    //                {
    //                    document.getElementById("img_"+ controlid+i).src = "Images/tick4.gif";
    //                }
                    if (i==index)
                    {
                        rows[i].className = "focusDIV";//sets the selected lookup css
                    }
                    else
                    {
                        if ((i % 2) == 0)
                            rows[i].className = "selectDIV1";//make other rows as it is  
                        else
                            rows[i].className = "selectDIV0";//make other rows as it is
                    }
                } 
                index--;//reduce to make up for the addition done       
                var ids = "hyper_" + controlid + index;//sets the control to focus
            }
            control2Focus = ids;//sets to the global variable
            document.getElementById("search_img_"+controlid).src = "Images/search.gif";//make sure that the lookup icon is restored
            setTimeout("doSetFocus()",300);//calls the function to set the focus after a delay
            //document.getElementById(ids).focus();
        }
        catch(Ex)
        {
            document.getElementById("search_img_"+controlid).src = "Images/search.gif";//make sure that the lookup icon is restored
        }
    }
    function doSetFocus()
    {
        try
        {
            document.getElementById(control2Focus).focus();//sets the focus
            //alert(control2Focus);
         }
         catch(Ex){}
    }

